﻿using System;
using System.Configuration;

namespace mvcForum.Core.Configuration {

	public class NamedComponentsElementCollection : ConfigurationElementCollection {

		public NamedComponent this[int index] {
			get { return (NamedComponent)BaseGet(index); }
			set {
				if (BaseGet(index) != null) {
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
			}
		}

		public void Add(NamedComponent component) {
			BaseAdd(component);
		}

		public void Clear() {
			BaseClear();
		}

		protected override ConfigurationElement CreateNewElement() {
			return new NamedComponent();
		}

		protected override Object GetElementKey(ConfigurationElement element) {
			return ((NamedComponent)element).Name;
		}

		public void Remove(NamedComponent component) {
			BaseRemove(component.Name);
		}

		public void RemoveAt(int index) {
			BaseRemoveAt(index);
		}

		public void Remove(string name) {
			BaseRemove(name);
		}
	}
}